package com.community.web.controller.house;

import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.core.page.TableDataInfo;
import com.community.domain.HouseEntity;
import com.community.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/house")
public class HouseController extends BaseController {
    @Autowired
    private HouseService houseService;
    @PreAuthorize("@ss.hasPermi('house:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseEntity house) {
        startPage();
        List<HouseEntity> list=houseService.selectHouseList(house);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('house:house:add')")
    @PostMapping("/addHouse")
    public AjaxResult addHouse(@RequestBody HouseEntity house) {
        return toAjax(houseService.addHouse(house));
    }
    @PreAuthorize("@ss.hasPermi('house:house:edit')")
    @PutMapping("/updateHouse")
    public AjaxResult updateHouse(@Validated @RequestBody HouseEntity house)
    {
        return toAjax(houseService.updateHouse(house));
    }
    @PreAuthorize("@ss.hasPermi('house:house:remove')")
    @DeleteMapping ("/{id}")
    public AjaxResult deleteById(@PathVariable int id) {
        return toAjax(houseService.deleteById(id));
    }

    @GetMapping("/houseType/{type}")
    public AjaxResult houseType(@PathVariable String type){
        Integer i = houseService.houseType(type);
        return AjaxResult.success(i);
    }
}
